# Maintainer: umarcor <unai.martinezcorral@ehu.eus>

_realname=prjtrellis
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.0.r1031.2f06397
pkgrel=2
pkgdesc="Documenting the Lattice ECP5 bit-stream format (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/YosysHQ/prjtrellis"
license=('MIT')
groups=("${MINGW_PACKAGE_PREFIX}-eda")
depends=(
  "${MINGW_PACKAGE_PREFIX}-boost"
  "${MINGW_PACKAGE_PREFIX}-python"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-boost"
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "git"
)

_commit="2f063976"
source=("${_realname}::git+https://github.com/YosysHQ/${_realname}.git#commit=${_commit}"
        "prjtrellis-db::git+https://github.com/YosysHQ/prjtrellis-db")
sha256sums=('SKIP'
            'SKIP')

pkgver() {
  cd "${_realname}"
  printf "1.0.r%s.%s" "$(git rev-list --count "${_commit}")" "$(git rev-parse --short "${_commit}")"
}

prepare () {
  cd "${_realname}"
  git submodule init
  git config submodule.database.url $srcdir/prjtrellis-db
  git submodule update
}

build() {
  cd "${srcdir}/${_realname}"/libtrellis

  MSYS2_ARG_CONV_EXCL='-DCMAKE_INSTALL_PREFIX=' cmake \
    -G "MSYS Makefiles" \
    -DCMAKE_PREFIX_PATH=${MINGW_PREFIX} \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    .
  make
}

check() {
  cd "${srcdir}/${_realname}"/libtrellis
  for item in ecpbram ecpmulti ecppack ecppll ecpunpack; do
    echo "> Check $item"
    ./"$item" --help
  done
}

package() {
  cd "${srcdir}/${_realname}"/libtrellis
  make DESTDIR="${pkgdir}" install

  _licenses="${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
  mkdir -p "${_licenses}"
  install -m 644 "${srcdir}/${_realname}"/COPYING "${_licenses}"
}
